package leetcode.editor.cn.q1_300.q150;

/**
 * @author qidi
 * @date 2022-02-10 17:09:41
 */
class Q0171_ExcelSheetColumnNumber {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int titleToNumber(String columnTitle) {
            char[] chars = columnTitle.toCharArray();
            int ans = 0;

            for (int i = chars.length - 1; i >= 0; i--) {
                char c = chars[i];
                ans += (c - 'A' + 1) * Math.pow(26, chars.length - i - 1);
            }

            return ans;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0171_ExcelSheetColumnNumber().new Solution();
        System.out.println(solution.titleToNumber("A"));
        System.out.println(solution.titleToNumber("AB"));
        System.out.println(solution.titleToNumber("ZY"));
        System.out.println(solution.titleToNumber("FXSHRXW"));
    }
}